package server.main.config.springsecurity.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import server.main.config.BeanInsert.Beans.PermissionRefresh;
import server.main.config.cache.MybatisPlusRedisCache;
import server.main.mapper.PermissionMapper;

/**
 * @auther MingHsZzz
 * @Date 2022/10/26  14:20
 * @project main
 * @description
 */
@Slf4j
@Component
@Order(value = 0)
public class InitPermission implements ApplicationRunner {

   @Autowired
   PermissionMapper permissionMapper;

   @Autowired
   MybatisPlusRedisCache mybatisPlusRedisCache;


   @Autowired
   PermissionRefresh permissionRefresh;





   @Override
   public void run(ApplicationArguments args) throws Exception {


      mybatisPlusRedisCache.clear("server.main.mapper.AccountMapper");
      mybatisPlusRedisCache.clear("server.main.mapper.AccountRoleMapper");
      mybatisPlusRedisCache.clear("server.main.mapper.RoleMapper");
      mybatisPlusRedisCache.clear("server.main.mapper.PermissionMapper");
      mybatisPlusRedisCache.clear("server.main.mapper.RolePermissionMapper");
//      System.out.println("*************清理缓存结束****************");
      log.info("清理缓存结束");
      permissionRefresh.setPermisiion();

      log.info("权限初始化完成");
   }
}
